// 枚举值
function formatterEnum(list, value) {
    if ((!value || value == "") && value != 0) return "";
    let index = list.findIndex((ele) => ele.value == value);
    return index > -1 ? list[index].name : value;
}

// 时间格式化
function formatDate(timestamp, format = 'YYYY-MM-DD') {
    const date = new Date(timestamp); // 时间戳（毫秒级）
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
    const day = String(date.getDate()).padStart(2, '0');

    // 时、分、秒
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');


    return format
        .replace('YYYY', year)
        .replace('MM', month)
        .replace('DD', day)
        .replace('HH', hours)
        .replace('mm', minutes)
        .replace('ss', seconds)
}

module.exports = {
    formatterEnum,
    formatDate,
}